import myRequest from '../request.js'
import dicts from '@/config/dicts.js'


// 充值明细
export const rechargeDetails = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/wallet/log', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 查询钱包余额
export const getwalletBalance = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/wallet/wallet', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 领取优惠券
export const getCoupons = (couponId) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/promotion/coupon/receive/' + couponId, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取可领取优惠券列表
export const getCouponList = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/promotion/coupon', 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取会员当前优惠券列表
export const getCurrentCouponList = (params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/promotion/coupon/getCoupons', 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取 历史足迹
export const getFootprint = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/member/footprint', 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取采购商公司信息
export const getPurchaserInfo = (id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/purchaser/purchaser/' + id, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取erp 资质 状态
export const getERPQualificationsStatus = (purchaserId) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/purchaser/purchaser/${purchaserId}/certifiedMaterials`, 'get').then(
			res => {
				resolve(res)
			}).catch((err) => {
			reject(err)
		})
	})
}
// 收货地址
export const shipToAddress = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + `/common/setting/ship/address/material`, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 收藏
// GOODS: 商品, STORE: 店铺
export const collectionList = (type, val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/member/collection/${type}`, 'get', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 取消收藏
export const cancelCollection = (type, id) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/member/collection/delete/${type}/${id}`, 'delete').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 上传图片
export const uploadImage = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.essential + '/common/common/upload/file', 'post', val, {
			headers: {
				"Content-type": "multipart/form-data"
			}
		}).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 获取 意见反馈 类型
export const getOpinionType = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/other/feedback/type', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 提交 意见反馈
export const submitOpinion = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/other/feedback', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}
// 登录
export const getSignIn = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/permit/member/login', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 验证码登录
export const codeLogin = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/permit/member/smsLogin', 'post', val).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 登录 2
export const getSignIn2 = () => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/permit/member/device', 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 邀请码 微信分享
export const shareInvitationCode = (businessCode) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/popularize/popularize/${businessCode}/share`, 'get').then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 获取邀请列表 
export const invitationList = (businessCode, params) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/members/invited/${businessCode}`, 'get', params).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}

// 绑定邀请人
export const bindInviter = (paramas) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/members/invited`, 'post', paramas).then(res => {
			resolve(res)
		}).catch((err) => {
			reject(err)
		})
	})
}